﻿#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

//给定一个字符串 s ，你需要反转字符串中每个单词的字符顺序，同时仍保留空格和单词的初始顺序。
//
//示例 1：
//
//输入：s = "Let's take LeetCode contest"
//输出："s'teL ekat edoCteeL tsetnoc"

int main2()
{
    string s("Let's take LeetCode contest");
    size_t pos = s.find(' ');
    reverse(s.begin(), s.begin() + pos);
    while (1)
    {
        int src_index = pos;
        pos = s.find(' ', pos + 1);
        if (pos == string::npos)
            break;
        reverse(s.begin() + src_index+1, s.begin() + pos);
    }
    reverse(s.begin() + s.rfind(' ') + 1, s.end());
	return 0;
}

#include <iostream>
using namespace std;
#include <string>
int main1()
{
    string s;
    getline(cin, s);
    int sz = s.size();
    string ret;
    size_t pos = s.rfind(' ');
    while (pos != string::npos)
    {
        ret += s.substr(pos+1, sz - pos - 1);
        ret += ' ';
        sz = pos;
        pos = s.rfind(' ', sz - 1);
    }
    ret += s.substr(0, sz);
    cout << ret <<"|"<< endl;
    return 0;
}